﻿using Castle.Core;
using Castle.Core.Interceptor;
using Castle.MicroKernel.Registration;
using XWord.Common;
using XWord.Common.Interfaces;

namespace XWord.ComponentBehaviors
{
    public static class RegistrationExtensions
    {
        /// <summary>
        /// 增加可被选中行为
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="componentRegistration">The component registration.</param>
        /// <returns></returns>
        public static ComponentRegistration<T> AddSelectableBehavior<T>(this ComponentRegistration<T> componentRegistration)
        {
            return componentRegistration.Proxy.AdditionalInterfaces(typeof(ISelectable)).Interceptors(new InterceptorReference(typeof(SelectableBehavior))).Last;
        }

        /// <summary>
        ///增加索引行为
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="componentRegistration">The component registration.</param>
        /// <returns></returns>
        public static ComponentRegistration<T> AddIndexableBehavior<T>(this ComponentRegistration<T> componentRegistration)
        {
            return componentRegistration.Proxy.AdditionalInterfaces(typeof(IIndexable)).Interceptors(new InterceptorReference(typeof(IndexableBehavior))).Last;
        }

        /// <summary>
        /// 增加可编辑行为
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="componentRegistration">The component registration.</param>
        /// <returns></returns>
        public static ComponentRegistration<T> AddEditingBehavior<T>(this ComponentRegistration<T> componentRegistration)
        {
            return componentRegistration.Proxy.AdditionalInterfaces(typeof(IEditing)).Interceptors(new InterceptorReference(typeof(EditingBehavior))).Anywhere;
        }

    }
}
